package com.uranus.common.common.service.impl;

import com.uranus.common.VO.ServiceContext;
import com.uranus.common.common.beans.CodeMessage;
import com.uranus.common.common.mapper.CodeMessageMapper;
import com.uranus.common.common.service.CodeMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uranus.common.constant.enums.LanguageEnum;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ybx
 * @since 2018-12-22
 */
@Service
public class CodeMessageServiceImpl extends ServiceImpl<CodeMessageMapper, CodeMessage> implements CodeMessageService {

    @Override
    public String queryCodeMessage(Integer code) {
        CodeMessage codeMessage=baseMapper.selectById(code);
        if(codeMessage!=null){
            LanguageEnum languageEnum= ServiceContext.getInstance().getLanguageEnum();
            if(languageEnum==null){
                return "";
            }
            switch (languageEnum){
                case zh_cn:
                    return codeMessage.getMessageZhCn();
                case en_us:
                    return codeMessage.getMessageEnUs();
                default:
                    return codeMessage.getMessageZhCn();
            }
        }
        return "error code message undefined,code:" + code.toString();
    }
}
